define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'withdraw/index' + location.search,
                    add_url: 'withdraw/add',
                    edit_url: 'withdraw/edit',
                    del_url: 'withdraw/del',
                    multi_url: 'withdraw/multi',
                    import_url: 'withdraw/import',
                    table: 'withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'withdraw_sn', title: __('Withdraw_sn'), operate: 'LIKE'},
                        {field: 'withdraw_type', title: __('Withdraw_type'), searchList: {"wechat":__('Withdraw_type wechat'),"alipay":__('Withdraw_type alipay')}, formatter: Table.api.formatter.normal},
                        {field: 'withdraw_info', title: __('Withdraw_info'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: 'up',
                                title: '处理',
                                text: '处理',
                                classname: 'btn btn-xs btn-info btn-ajax',
                                icon: 'fa fa-list',
                                url: 'withdraw/audit?status=1',
                                confirm: '是否同意该请求？', //点击按钮后的确认框，支持function
                                visible: function (row) {
                                    // 判断当前行数据中的 status 字段的值是否等于 1
                                    if (row.status == 0) {
                                        // return true 代表显示
                                        return true;
                                    }
                                },
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    return true;
                                },
                                //callback: function (data) {
                                //    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                //}
                            },{
                                name: 'down',
                                title: '驳回',
                                text: '驳回',
                                classname: 'btn btn-xs btn-primary btn-ajax',
                                icon: 'fa fa-list',
                                url: 'withdraw/audit?status=-1',
                                confirm: '是否同意该请求？', //点击按钮后的确认框，支持function
                                visible: function (row) {
                                    // 判断当前行数据中的 status 字段的值是否等于 1
                                    if (row.status == 0) {
                                        // return true 代表显示
                                        return true;
                                    }
                                },
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    return true;
                                },
                                //callback: function (data) {
                                //    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                //}
                            },{
                                name: 'down',
                                title: '已处理',
                                text: '已处理',
                                classname: 'btn btn-xs btn-primary btn-ajax',
                                icon: 'fa fa-list',
                                url: 'withdraw/audit?status=2',
                                confirm: '是否同意该请求？', //点击按钮后的确认框，支持function
                                visible: function (row) {
                                    // 判断当前行数据中的 status 字段的值是否等于 1
                                    if (row.status == 1) {
                                        // return true 代表显示
                                        return true;
                                    }
                                },
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    return true;
                                },
                                //callback: function (data) {
                                //    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                //}
                            }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
